package Utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StringVerification {
    public static void main(String[] args) {
        System.out.println(StringVerification.UserNameVerification("liao123_"));
        System.out.println(StringVerification.PassWordVerification("liao123_","liao123_"));
        System.out.println(EmailVerification("2777258062@qq.com"));

    }
    public static boolean UserNameVerification(String username){
        if (username == null){
            return false;
        }
        if (username.length() > 10 || username.length() < 6){
            return false;
        }
        if (!username.contains("_")){
            return false;
        }
        // 验证有没有数字
        String number = "\\d";
        Pattern compile = Pattern.compile(number);
        Matcher matcher = compile.matcher(username);
        if (!matcher.find()){
            return false;
        }
        //验证有没有字符
        String letter ="[a-zA-Z]";
        Pattern compile1 = Pattern.compile(letter);
        Matcher matcher1 = compile1.matcher(username);
        if (!matcher1.find()){
            return false;
        }
        String all = "\\w+";
        Pattern compile2 = Pattern.compile(all);
        Matcher matcher2 = compile2.matcher(username);
        if (!matcher2.matches()){
            return false;
        }
        return true;
    }
    public static boolean PassWordVerification(String username,String other){
        if (username == null || other == null){
            return false;
        }
        if (!username.equals(other)){
            return false;
        }
        if (username.length() > 10 || username.length() < 6){
            return false;
        }
        if (!username.contains("_")){
            return false;
        }
        // 验证有没有数字
        String number = "\\d";
        Pattern compile = Pattern.compile(number);
        Matcher matcher = compile.matcher(username);
        if (!matcher.find()){
            return false;
        }
        //验证有没有字符
        String letter ="[a-zA-Z]";
        Pattern compile1 = Pattern.compile(letter);
        Matcher matcher1 = compile1.matcher(username);
        if (!matcher1.find()){
            return false;
        }
        String all = "\\w+";
        Pattern compile2 = Pattern.compile(all);
        Matcher matcher2 = compile2.matcher(username);
        if (!matcher2.matches()){
            return false;
        }
        return true;
    }
    public static boolean EmailVerification(String email){
        String regex = "\\w+@[\\w_#$%*]+.\\w+";
        Pattern compile = Pattern.compile(regex);
        Matcher matcher = compile.matcher(email);
        if (matcher.matches()){
            return true;
        }
        return false;
    }
}
